layui.use(['form','layer'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;
    $(function(){
        var id = $(".id").val();
        // console.log(id);
        // 根据ID查询网站信息并显示在表单中
        $.ajax({
            type: "get",
            url: "/mytools/websiteManager/getWebsiteInfo?id="+id,
            contentType: 'application/json;charset=UTF-8',
            success: function(result){
                var msg = JSON.parse(result);
                if(msg.count==1){
                    var websetInfo = msg.data[0];
                    $(".name").val(websetInfo.name);  //站点
                    $(".url").val(websetInfo.url);  //网址
                    $(".type input[value="+websetInfo.type+"]").prop("checked","checked");  //类型
                    $(".state input[value="+websetInfo.state+"]").prop("checked","checked");  //状态
                    form.render();
                }else{
                    console.log("未发现网站信息");
                }

            }
         });
    })
    // 提交修改后的信息
    form.on("submit(editWebsite)",function(data){
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        // console.log(JSON.stringify(data.field));
        $.ajax({
            type: "POST",
            url: "/mytools/websiteManager/updWebsiteById",
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify(data.field),
            success: function(msg){
                console.log( msg );
            }
         });
        setTimeout(function(){
            top.layer.close(index);
            top.layer.msg("网站修改成功！");
            layer.closeAll("iframe");
            //刷新父页面
            parent.location.reload();
        },2000);
        return false;
    })
 
    //格式化时间
    function filterTime(val){
        if(val < 10){
            return "0" + val;
        }else{
            return val;
        }
    }
    //定时发布
    var time = new Date();
    var submitTime = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());

})